package com.ruoyi.message.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.message.domain.IotMessage;
import com.ruoyi.message.service.IIotMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息通知Controller
 * 
 * @author wujiale
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/privacy/privacy")
public class IotMessageController extends BaseController
{
    @Autowired
    private IIotMessageService iotMessageService;

    //已读
    @GetMapping("/read")
    public AjaxResult read(Long MessageId)
    {
        iotMessageService.updateStatus(MessageId);
        return success();
    }
    @GetMapping("/message")
    public TableDataInfo listUser(IotMessage iotMessage)
    {
        Long userId = SecurityUtils.getUserId();
        iotMessage.setUserId(userId);
        startPage();
        List<IotMessage> list = iotMessageService.selectAllMessageList(iotMessage);
        return getDataTable(list);
    }
    /**
     * 查询消息通知列表
     */
    @PreAuthorize("@ss.hasPermi('privacy:privacy:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotMessage iotMessage)
    {
        startPage();
        List<IotMessage> list = iotMessageService.selectIotMessageList(iotMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息通知列表
     */
    @PreAuthorize("@ss.hasPermi('privacy:privacy:export')")
    @Log(title = "消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotMessage iotMessage)
    {
        List<IotMessage> list = iotMessageService.selectIotMessageList(iotMessage);
        ExcelUtil<IotMessage> util = new ExcelUtil<IotMessage>(IotMessage.class);
        util.exportExcel(response, list, "消息通知数据");
    }

    /**
     * 获取消息通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('privacy:privacy:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(iotMessageService.selectIotMessageByMessageId(messageId));
    }

    /**
     * 新增消息通知
     */
    @PreAuthorize("@ss.hasPermi('privacy:privacy:add')")
    @Log(title = "消息通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotMessage iotMessage)
    {
        return toAjax(iotMessageService.insertIotMessage(iotMessage));
    }

    /**
     * 修改消息通知
     */
    @PreAuthorize("@ss.hasPermi('privacy:privacy:edit')")
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotMessage iotMessage)
    {
        return toAjax(iotMessageService.updateIotMessage(iotMessage));
    }

    /**
     * 删除消息通知
     */
    @PreAuthorize("@ss.hasPermi('privacy:privacy:remove')")
    @Log(title = "消息通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(iotMessageService.deleteIotMessageByMessageIds(messageIds));
    }
}
